<template>
  <div class="editForm-wrapper">
    <el-dialog
      :title="title"
      width="570px"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="editVisible"
    >
      <el-form
        label-width="129px"
        :rules="datasche"
        ref="poundscheEditForm"
        :model="poundscheEditForm"
      >
        <el-form-item label="磅房名称:" prop="name">
          <el-input v-model="poundscheEditForm.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="排版制:" prop="poundSchedule.dutyInterval">
          <el-select clearable v-model="poundscheEditForm.poundSchedule.dutyInterval">
            <el-option
              v-for="item in  $dictUtils.getDictList('schedule')"
              :key="item.value"
              :label="item.label"
              :value="Number(item.value)">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="起始时间:" prop="poundSchedule.startTime">
          <el-time-select
            v-model="poundscheEditForm.poundSchedule.startTime"
            :picker-options="{
              start: '00:00',
              step: '00:30',
              end: '24:00'
            }">
          </el-time-select>
        </el-form-item>

        <el-form-item label="交班等待时长:" prop="poundSchedule.shiftWaitTime" >
          <el-input v-model="poundscheEditForm.poundSchedule.shiftWaitTime"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <div class="footer-input">
        <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick >确定</el-button>
        <el-button size="small" @click="editVisible = false">取消</el-button>
        </div>

      </span>
    </el-dialog>
  </div>

</template>

<script>

export default {

  data () {
    return {
      method: '',
      detailsVisible: false,
      title: '',
      poundscheEditForm: {
        poundSchedule: {
          shiftWaitTime: '',
          startTime: '',
          dutyInterval: '',
          id: ''
        },
        name: '',

        poundRoomId: '',
        id: ''
      },
      editVisible: false,
      datasche: {
        'poundSchedule.dutyInterval': [{ required: true, message: '请选择排班', trigger: 'change' }],
        'poundSchedule.startTime': [{ required: true, message: '请选择起始时间', trigger: 'change' }],
        'poundSchedule.shiftWaitTime': [{ required: true, message: '请输入交接班等待时长', trigger: 'blur' }]
      }
    }
  },
  methods: {
  	handleClose(done) {
		this.$Msg.confirm({
			title:'您确定要关闭吗？',
			content:this.GLOBAL.FORM_CLOSE_TIPS,
			confirmCall:()=>{
				done();
			}
		})
	},
    init (method, obj, row) {
      this.poundscheEditForm.poundRoomId = obj
      this.poundscheEditForm.id = ''
      if (row.poundSchedule) {
        this.poundscheEditForm = row
      } else {
        this.poundscheEditForm = row
        let poundSchedule = {
            shiftWaitTime: '',
            startTime: '',
            dutyInterval: '',
            id: ''
          }
          this.$set(this.poundscheEditForm, 'poundSchedule', poundSchedule)
        // this.poundscheEditForm.poundSchedule = poundSchedule
      }

      // this.poundscheEditForm = row
      this.method = method
      if (method === 'add') {
        this.title = '设置磅房'
        this.editVisible = true
      } else if (method === 'edit') {
        this.title = '设置排班'
        this.editVisible = true
        this.$nextTick(() => {
          if (method === 'edit') { // 修改或者查看
            console.log(this.poundscheEditForm)
            // console.log(row.poundSchedule.dutyInterval)

            // this.$http({
            //   url: `/basis/poundroom/queryById?id=${this.poundscheEditForm.poundRoomId}`,
            //   method: 'get'
            // }).then(({data}) => {
            //   this.poundscheEditForm = this.recover(this.poundscheEditForm, data.PoundRoom)
            //   this.poundscheEditForm.oldLoginName = this.poundscheEditForm.loginName
            // })
          }
        })
      }
    },
    // 表单提交
    doSubmit () {
      this.$refs['poundscheEditForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.$http({
            url: `/basis/poundsche/save`,
            method: 'post',
            data: this.poundscheEditForm
          }).then(({ data }) => {
            this.loading = false
            if (data && data.success) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.editVisible = false
              this.addChildVisible = false
              this.$emit('refreshDataList')
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>



</style>
